<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>calc.html</title>
<style>
input {
	width: 50px;
	height: 50px;
}

#c {
	width: 105px;
}

#r {
	height: 105px;
}

#result{
	width:275px;
	
	
	border:5px solid #aadddd;
	
	
}
</style>


<script>
//메모리에 관련된 변수
	var memory=0;
	function calc() {
		var r=document.getElementById("result");
		r.value=eval(r.value);
	}
	
	function cls(){
		var r=document.getElementById("result");
		r.value="";
	}
	
	function mem(v) {//메모리에 관련된 처리함수
		var r=document.getElementById("result");
	
		switch(v){
		
		case 'MS':
			memory=Number(r.value);
			break;
		case 'MR':
			r.value=memory;
			break;
		case 'MC':
			memory=0;
			break;
		case 'M+':
			memory +=Number(r.value);
			break;
		case 'M-':
			memory -=Number(r.value);
			break;
		}
	}
	


	function oper(v) {
		var r=document.getElementById("result");
		var temp= r.value+v;
		r.value=temp;
		
	}


</script>
</head>
<body>
	<div id='main'>
		<input tex='text' id='result'>
	</div>

	<table border=2px cellspacing=1px width='258' bordercolor='#aabbcc'>
		<tr bgcolor='#aabbcc'>
			<td><input type="button" onclick="mem(this.value)" value='MC'></td>
			<td><input type="button" onclick="mem(this.value)" value='MR'></td>
			<td><input type="button" onclick="mem(this.value)" value='MS'></td>
			<td><input type="button" onclick="mem(this.value)" value='M+'></td>
			<td><input type="button" onclick="mem(this.value)" value='M-'></td>
		</tr>



		<tr bgcolor='#aabbcc'>
			<td><input type="button" onclick="oper('bs')" value='←'></td>
			<td><input type="button" onclick="cls()" value='CE'></td>
			<td><input type="button" onclick="cls()" value='C'></td>
			<td><input type="button" onclick="oper(this.value)"  value='±'></td>
			<td><input type="button" onclick="oper(this.value)"  value='√'></td>
		</tr>


		<tr bgcolor='#aabbcc'>
			<td><input type="button" onclick="oper(this.value)" value='7'></td>
			<td><input type="button" onclick="oper(this.value)" value='8'></td>
			<td><input type="button" onclick="oper(this.value)" value='9'></td>
			<td><input type="button" onclick="oper(this.value)" value='/'></td>
			<td><input type="button" onclick="oper(this.value)" value='%'></td>
		<tr bgcolor='#aabbcc'>
			<td><input type="button" onclick="oper(this.value)" value='4'></td>
			<td><input type="button" onclick="oper(this.value)" value='5'></td>
			<td><input type="button" onclick="oper(this.value)" value='6'></td>
			<td><input type="button" onclick="oper(this.value)" value='*'></td>
			<td><input type="button" onclick="oper(this.value)" value='1/x'></td>
		</tr>

		<tr bgcolor='#aabbcc'>
			<td><input type="button" onclick="oper(this.value)" value='1'></td>
			<td><input type="button" onclick="oper(this.value)" value='2'></td>
			<td><input type="button" onclick="oper(this.value)" value='3'></td>
			<td><input type="button" onclick="oper(this.value)" value='-'></td>
			<td rowspan="2"><input type="button" id='r' onclick="calc()" value='='></td>
		</tr>

		<tr bgcolor='#aabbcc'>
			<td colspan="2"><input type="button" id='c' onclick="oper(this.value)" value='0'></td>
			<td><input type="button" onclick="oper(this.value)"  value='.'></td>
			<td><input type="button" onclick="oper(this.value)" value='+'></td>
		</tr>

	</table>

</body>
</html>